import { ref, reactive } from 'vue'
import { processApi } from '@/api/modules/process'

export function useProcess() {
    const loading = ref(false)
    const error = ref(null)
    const processData = ref(null)

    const getProcessMap = async () => {
        loading.value = true
        error.value = null

        try {
            const result = await processApi.getProcessMap()
            processData.value = result.data
            return result
        } catch (err) {
            error.value = err.message || '请求失败'
            throw err
        } finally {
            loading.value = false
        }
    }

    const submitProcess = async (data) => {
        loading.value = true
        error.value = null

        try {
            const result = await processApi.submitProcess(data)
            return result
        } catch (err) {
            error.value = err.message || '提交失败'
            throw err
        } finally {
            loading.value = false
        }
    }

    return {
        loading,
        error,
        processData,
        getProcessMap,
        submitProcess
    }
}
